/**
 * 
 */
package com.ntv.presentation.spring.web.backoffice;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.ntv.domain.INews;
import com.ntv.domain.IUser;
import com.ntv.domain.Login;
import com.ntv.service.DomainException;
import com.ntv.service.news.INewsAppService;

/**
 * @author Vedamoorthi Vairam
 *@since 12/02/2009
 */
@Controller
@SessionAttributes("userSession")
public class BackOfficeAstrologyController {	

	@Autowired
	private INewsAppService newsAppService;
	
	private static final String MA_LOGIN= "login";
	@RequestMapping("/backOfficeAstrologyList.html")
	public ModelAndView  form(@ModelAttribute(MA_LOGIN) Login  login, HttpServletRequest request) {
		IUser user = (IUser)request.getSession().getAttribute("userSession");
		
		if (user == null)
		{
			login.setTarget("backoffice.html");
			ModelAndView mav = new ModelAndView("signin");
			return mav;
		}
		else
		{
			try 
			{
				List<INews> newsList = newsAppService.findAllNews();
				ModelAndView mav = new ModelAndView("backoffice.astrology.list");
				Map model1 = new HashMap();
				model1.put("news", newsList);	
				return mav;
			} 
			catch (DomainException e) {
				return new ModelAndView("home");
			}
			
		}
	}
	/**
	 * @param newsAppService the newsAppService to set
	 */
	public void setNewsAppService(INewsAppService newsAppService) {
		this.newsAppService = newsAppService;
	}
	
}
